import { FC,useEffect, useMemo, useState } from 'react';
import { useSelector,useDispatch } from 'react-redux';
import { IState } from '../store/reducer';
import { ActionType } from '../store/actionTypes';
import News from '../componenst/News'

const Index: FC<any> = (props:any): JSX.Element => {

    const dispatch=  useDispatch();

    //useSelector 使用状态

     let token= useSelector((state:IState)=>state.token)
     let user= useSelector((state:IState)=>state.userInfo)
     let list= useSelector((state:IState)=>state.list)
     const [title,setTitle]=useState("aaa");

     //修改状态

     const update=()=>{

        setTitle("cccc");
        dispatch({type:ActionType.修改token,data:"mmmmmmm"})
       
     }
     const updateUser=()=>{

        dispatch({type:ActionType.修改用户,data:{name:"李四"}})

     }
     const add=()=>{

        dispatch({type:ActionType.添加,data:9})

     }


    useEffect(()=>{
    },[])

    return (
      <div>
        用户管理
        <div>

            <div>
                <ul>
                 
                    {
                        list.map((item)=>(
                            <li key={item}>{item}</li>
                        ))
                    }
                </ul>
            </div>
            {token}

            <div>
                {user.name}
            </div>

            <button onClick={update}>修改</button>
            <button onClick={updateUser}>修改用户</button>
            <button onClick={add}>添加</button>
        </div>
      </div>
    )
}
export default Index;